import { constantRoutes, asyncRoutes } from '@/router'

const state = {
  routes: constantRoutes // 菜单
}
const mutations = {
  setRoutes(state, otherRoutes) {
    state.routes = [...constantRoutes, ...otherRoutes]
  }
}
const actions = {
  filterRoutes(context, menu) {
    // nemu与动态路由规则过滤  otherRoutes
    // context.commit('setRoutes',otherRoutes)
    // return otherRoutes
    const otherRoutes = asyncRoutes.filter(item => {
      return menu.includes(item.children[0].name)
    })

    // otherRoutes = [{},{},{}]

    context.commit('setRoutes', otherRoutes)

    return otherRoutes // 返回数据 目的是动态添加路由router.addRoutes(otherRoutes)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
